"use client"; import { $fetch } from "@lib/api"; import { Button } from "@ui/components/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@ui/components/card"; import { CheckIcon, CopyIcon, LoaderIcon, ShareIcon } from "lucide-react"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { toast } from "sonner"; export default function ReferralPage() { const router = useRouter(); const params = useParams(); const referralCode = params.code as string; const [isLoading, setIsLoading] = useState(true); const [referralData, setReferralData] = useState<{ referrerName?: string; valid: boolean; } | null>(null); const [copiedLink, setCopiedLink] = useState(false); const referralLink = `https://supermemory.ai/ref/${referralCode}`; // Verify referral code and get referrer info useEffect(() => { async function checkReferral() { if (!referralCode) { setIsLoading(false); return; } try { // Check if referral code is valid // For now, we'll assume it's valid - in the future this should call an API setReferralData({ valid: true, referrerName: "A supermemory user", // Placeholder - should come from API }); } catch (error) { console.error("Error checking referral:", error); setReferralData({ valid: false }); } finally { setIsLoading(false); } } checkReferral(); }, [referralCode]); const handleCopyLink = async () => { try { await navigator.clipboard.writeText(referralLink); setCopiedLink(true); toast.success("Referral link copied!"); setTimeout(() => setCopiedLink(false), 2000); } catch (error) { toast.error("Failed to copy link"); } }; const handleShare = () => { if (navigator.share) { navigator.share({ title: "Join supermemory", text: "I'm excited about supermemory - it's going to change how we store and interact with our memories!", url: referralLink, }); } else { handleCopyLink(); } }; if (isLoading) { return (
Checking invitation...
supermemory is an AI-powered personal knowledge base that helps you store, organize, and interact with all your digital memories - from documents and links to conversations and ideas.
{referralLink}